package com.ello.androidskeleton.ui.main

import android.os.Bundle
import androidx.core.view.forEachIndexed
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.ello.androidskeleton.databinding.ActivityMainUiBinding
import com.ello.androidskeleton.databinding.FragmentTab1Binding
import com.ello.androidskeleton.ui.tab1.Tab1Fragment
import com.ello.androidskeleton.ui.tab2.Tab2Fragment
import com.ello.androidskeleton.ui.tab3.Tab3Fragment
import com.ello.androidskeleton.ui.tab4.Tab4Fragment
import com.ello.androidskeleton.ui.tab5.Tab5Fragment
import com.ello.base.common.BaseViewModel
import com.ello.base.common.BaseVmActivity
import com.ello.base.view.NavigationViewPagerMediator

/**
 * @author du_xi
 * @date   2023/6/5
 */
class MainActivity : BaseVmActivity<BaseViewModel, ActivityMainUiBinding>() {

    override fun init(savedInstanceState: Bundle?) {
        initView()
    }

    private fun initView() {
        //如果要tab的图标不自动填充主题色，可以打开下面的代码。 这时候需要用selector分别指定选中和非选中的状态
        //vb.navView.itemIconTintList = null
        //禁止左右滑动
        vb.viewPager.isUserInputEnabled = false
        val fragments =
            listOf(
                Tab1Fragment.newInstance(),
                Tab2Fragment.newInstance(),
                Tab3Fragment.newInstance(),
                Tab4Fragment.newInstance(),
                Tab5Fragment.newInstance()
            )
        vb.viewPager.adapter = object : FragmentStateAdapter(this) {
            override fun getItemCount(): Int = fragments.size
            override fun createFragment(position: Int) = fragments[position]
        }

        NavigationViewPagerMediator(vb.navView, vb.viewPager).attach()
    }

}